/************************************************* A S S I G N M E N T ******************************************************
  			C A L C U L A T I O N    O F    P O W E R   O F   A   G I V E N    N U M B E R 

				TEACHER : PROF. B.P SINHA.
				STUDENT : Abhay kumar(mtc0415).
****************************************************************************************************************************/
#include <stdio.h>
#include <conio.h>
#define SIZE 20
int main()

	{
		int  num , index , temp , i , j , lsb, bin_value[SIZE] , mult_count = 0;

		printf("\nENTER THE NUMBER AND ITS INDEX.....\n");
		scanf("%d%d",&num,&index);
		
		if( index +index <= 2 )

		{
			printf("\n**** RESULT = %d\n**** NO OF MULTIPLICATION = 0 \n",(index==1 ? num : 1) );
			exit(0);

		}
		
		for( temp = num , j=lsb = index & 1 , index = index >> 1;  index != 1 ; index=index >> 1)
		{
			if (lsb == 1) 

			{
				temp = temp * temp * num ;
				mult_count = mult_count + 2 ;
			}
			else

			{
				temp = temp * temp ;
				mult_count ++ ;
			}

			lsb = index & 1;
		

		}

		if( j == 1)

			temp = temp *temp * num ;
		else
			temp = temp * temp ;
	printf("\n\n**** RESULT = %d \n**** NO OF MULTICATION = %d \n\n",temp,mult_count);

}

	
/************************************************** R E S U L T S ***********************************************************

[mtc0415@www abhay]$ ./a.out
 
ENTER THE NUMBER AND ITS INDEX.....
2
0
 
**** RESULT = 1
**** NO OF MULTIPLICATIONS = 0
 
[mtc0415@www abhay]$ ./a.out
 
ENTER THE NUMBER AND ITS INDEX.....
4
1
 
**** RESULT = 4
**** NO OF MULTIPLICATIONS =  0
 
[mtc0415@www abhay]$ ./a.out
 
ENTER THE NUMBER AND ITS INDEX.....
2
10
 
**** RESULT = 1024
**** NO OF MULTIPLICATIONS =  4
 
[mtc0415@www abhay]$ ./a.out
 
ENTER THE NUMBER AND ITS INDEX.....
2
9
 
**** RESULT = 512
**** NO OF MULTIPLICATIONS =  4
 
[mtc0415@www abhay]$ ./a.out
 
ENTER THE NUMBER AND ITS INDEX.....
2
11
 
**** RESULT = 2048
**** NO OF MULTIPLICATIONS =  5
 
[mtc0415@www abhay]$
[mtc0415@www abhay]$ ./a.out
 
ENTER THE NUMBER AND ITS INDEX.....
3
5
 
**** RESULT = 243
**** NO OF MULTIPLICATIONS =  3
 
[mtc0415@www abhay]$
[mtc0415@www abhay]$ ./a.out
 
ENTER THE NUMBER AND ITS INDEX.....
3
7
 
**** RESULT = 2187
**** NO OF MULTIPLICATIONS =  4
 
*/
